<?php
namespace app\beautiful\model\member;
use app\common\model\CommonModel;

class MemberSnapUpModel extends CommonModel{
    protected  $name = 'beautiful_member_snap_up';
    protected  $pk   = 'member_snap_up_id';
    protected $type=[
        'pay_info' => 'array',
    ];

    public function member()
    {
        return $this->hasOne(MemberModel::class,'member_id','member_id');
    }


    public function getStatusMeansAttr($value,$data)
    {
        $today=date("Y-m-d");
        if($data['status']==8) return '已完成';
        if($data['status']==1 && $data['valid_end_time']>=$today) return '待消费';
        if($data['status']==1 && $data['valid_end_time']<$today) return '已过期';
        return '状态异常';
    }
    //前台需要
    public function getStatusAnotherAttr($value,$data){
       $today=date("Y-m-d");
       if($data['status'] == 8) return 8;
       if($data['status']==1 && $data['valid_end_time']>=$today) return 1;
       return -1;
    }

    public function getPayTimeFormatAttr($value,$data){
        return $data['pay_time'] ? date('Y-m-d H:i:s',$data['pay_time']) : '-';
    }

    public function getPayTypeMeanAttr($value,$data)
    {
        $type_means=[
            'weixin'=>'微信支付',
            'money'=>'余额支付',
            'offline' => '代客下单',
        ];
        return $type_means[$data['pay_type']] ?? '-';
    }
}